<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>设备维修申请</title>
	<link rel="stylesheet" type="text/css" href="../../../resource/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="../../../resource/css/user_css/publicStyle.css">
	<link rel="stylesheet" type="text/css" href="../../../resource/layui/css/layui.css"/>
	<link rel="stylesheet" type="text/css" href="../../../resource/css/niubility.css"/>
	<script type="text/javascript" src="../../../resource/layui/layui.js"></script>
	<!-- 购入、调入,调出，维修维护，报损报废相同的css样式 -->
	<link rel="stylesheet" type="text/css" href="../../../resource/css/user_css/purchase_diaoRu_style.css"/>
</head>
<body>
	<form action="" method="post" id="formAddDevice">
		<div class="boxOne">
			<div class="form-group">
				<label>请选择设备类别:</label>
				<select  class="form-control" name="equipmentCategory" id="category">
					<option value="-1">--未选择--</option>
				</select>
			</div>
			<div class="form-group" >
				<label>请选择设备名称:</label>
				<select  class="form-control" name="equipmentName" id="name">
					<option value="-1">--未选择--</option>
				</select>
			</div>
			<div class="form-group" >
				<label>请选择设备编号:</label>
				<select  class="form-control" name="equipmentNo" id="number">
					<option value="-1">--未选择--</option>
				</select>
			</div>
		    <div class="form-group">
		      	  <label >维修日期:</label>
		          <input type="date" style="width:300px;" class="form-control" name="repairDate" id="repairDate">
		    </div>
		    <div class="form-group" >
		      	   <label >修护原因:</label>
		          <textarea name="repairReason" id="repairReason" class="form-control" style="width: 300px;height: 90px;"></textarea>
			</div>
		</div>

		<div class="boxOne">
			<div class="form-group">
		      	  <label for="repairPlace">修护地点:</label>
		          <input type="text" class="form-control" name="repairPlace" id="repairPlace"  placeholder="可选填"/>
		    </div>
		    <div class="form-group">
		      	  <label for="repairMan">修护人员:</label>
		          <input type="text" class="form-control" name="repairMan" id="repairMan"  placeholder="可选填"/>
		    </div>
		    <div class="form-group">
		      	  <label for="repairMoney">修护费用:</label>
		          <input type="text" class="form-control" name="repairMoney" id="repairMoney">
		    </div>
		</div>
		<div style="clear: both;"></div>
	    <button type="button" class="btn btn-default" id="btn">提交</button>
	</form>
	<script type="text/javascript" src="../../../resource/js/jquery.min.js"></script>
	<!-- 静态url路径 -->
	<script type="text/javascript" src="../../../resource/js/static_url.js"></script>
	<!-- 表单序列化提交：购入、调入、调出、维修维护、报损报废、装让 -->
	<script type="text/javascript" src="../../../resource/js/user_js/user_post_serialize.js"></script>
	<!--设备类别 + 设备名称 + 设备编号-->
	<script type="text/javascript" src="../../../resource/js/user_js/equipmentTableThree.js"></script>
	<!--表单验证：-->
	<script type="text/javascript">
/*------------------必填字段：三级联动 ，维修日期 ，维修费用------------------------*/
		$("#btn").click(function(){
		    // ------三级联动
            var category = $("#category").val();
            var name = $("#name").val();
            var number = $("#number").val();
            if(category==-1){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，要正确选择设备类别', '#category', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return;
            }
            if(name==-1){

                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，要正确选择设备名称', '#name', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return;
            }
            if(number==-1){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，要正确选择设备编号', '#number', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return;
            }
            // ------维修日期: （1）不能为空 （2）不能大于当前时间
			var repairDate = $("#repairDate").val();
            if(repairDate == ''){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，填写您忘记填写维修日期了', '#repairDate', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return;
            }
            var db = new Date(repairDate.replace(/-/g, "/")); //  " /-/g " 般用于格式化日期,如 2016-1-1 格式化为 2016/1/1
            var d = new Date();
            var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
            if(Date.parse(str)<Date.parse(db)){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，维修时间不能大于当前时间', '#repairDate', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return ;
            }
            // ----维修费用：（1）不能为空
			var repairMoney = $("#repairMoney").val();
            if(repairMoney == ''){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，维修费用不能为空', '#repairMoney', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });

                return;
			}else if(repairMoney.length > 9){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，维修费用太高了，高到提交不了哦！', '#repairMoney', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return;
			}
            for(let i=0;i<repairMoney.length;i++)
            {
                if(!(repairMoney.charAt(i)>=0 && repairMoney.charAt(i)<=9)){
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.tips('亲，只能填数字哦', '#repairMoney', {
                            tips: [1, '#333'],
                            time: 2500,
                        });
                    });
                    return;
                }
            }



/*------------选填字段： 维修地点，维修原因，维修人员-----------------------------------*/
            var repairPlace = $("#repairPlace").val();
            if(repairPlace.lenthg>25){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，地点名字不能超过25个字符', '#repairPlace', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return ;
            }
            var repairMan = $("#repairMan").val();
            if(repairMan.lenthg>10){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，维修人员的名字不能超过10个字符', '#repairMan', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return ;
            }
            var repairReason = $("#repairReason").val();
            if(repairReason.lenthg>150){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.tips('亲，维修理由不能超过150个字符', '#repairReason', {
                        tips: [1, '#333'],
                        time: 2500,
                    });
                });
                return ;
            }
            //--- 提交数据
            post_serialize(user_repair_post);
		});

		// 设置默认时间
		var myDate = new Date();
		var year = myDate.getFullYear();
		var month = myDate.getMonth()+1;
		var day = myDate.getDate();
		//判断 月份、天数 <10的时候前面加 0
		if(month < 10){
			month = "0"+month;
		}
		if(day < 10){
			day = "0"+day;
		}
		var time = year +"-"+ month +"-"+ day;
		$("#repairDate").val(time);
	</script>
</body>
</html>